<template>
    <div>
        <el-breadcrumb>
            <el-breadcrumb-item>首页</el-breadcrumb-item>
        </el-breadcrumb>
        <span>欢迎登录XXX学校</span>
    </div>
    <div class="info">
        <div class="item">
            <el-badge :value="aeditlist.length" class="item">
                <el-button>学校通知</el-button>
            </el-badge>
            <el-scrollbar height="180px">
                <div v-for="(item, i) in aeditlist" :key="i" class="scrollbar-demo-item"
                    :class="{ important: item.type == 2 }" @click="showdailg(item.val)">
                    <div class="edititem">{{ item.title }}</div>
                    <div class="edititem">{{ item.create_time.slice(0, 16) }} </div>
                </div>
            </el-scrollbar>
        </div>
        <el-divider border-style="double" />
        <div class="item" v-if="userstore.userinfo.roleid == 4">
            <el-badge :value="teditlist.length" class="item">
                <el-button>辅导员通知</el-button>
            </el-badge>
            <el-scrollbar height="180px">
                <div v-for="(item, i) in teditlist" :key="i" class="scrollbar-demo-item"   @click="showdailg(item.val)"
                    :class="{ important: item.type == 2 }">
                    <div class="edititem">{{ item.title }}</div>
                    <div class="edititem">{{ item.create_time.slice(0, 16) }} </div>
                </div>
            </el-scrollbar>
        </div>
    </div>
    <el-dialog
    v-model="isshow"
    title="查看通知"
    width="500"
    >
<span v-html="text" style="height: 400px; display: block;"></span>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="isshow = false">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang='ts'>
import { getaedit, gettedit } from '@/apis/edit';
import { onMounted, ref } from 'vue';
// @ts-ignore
import { Userstore } from '@/stores/user.js';
const isshow = ref(false)
const text =ref('')
const showdailg =(val:any)=>{
isshow.value = true
text.value = val
}
const userstore = Userstore()
const aeditlist = ref<any>([])
const teditlist = ref<any>([])
const getaeditlist = async () => {
    const res = await getaedit()
    aeditlist.value = res.data.data.reverse()
    console.log(res);
    
}
const getteditlist = async () => {
    const res = await gettedit({ teacherid: userstore.userinfo.tecid })
    teditlist.value = res.data.data.reverse()
}
onMounted(() => {
    getaeditlist()
    if (userstore.userinfo.roleid == 4) {
        getteditlist()
    }
})

</script>
<style lang='scss' scoped>
.el-breadcrumb {
    margin-bottom: 10px;
}

.scrollbar-demo-item {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 50px;
    margin: 10px;
    text-align: center;
    border-radius: 4px;
    background: var(--el-color-primary-light-9);
    color: var(--el-color-primary);
}

.important {
    color: red;
}

.edititem {
    width: 50%;
    height: 100%;
    line-height: 40px;
    text-align: center;
}

.info {
    margin-top: 15px;
}
</style>